// server.js
import express from 'express';
import { ExpressPeerServer } from 'peer'
import http from 'http';
import cors from 'cors';
const app = express();
const server = http.createServer(app);

// 配置PeerJS服务器
const peerServer = ExpressPeerServer(server, {
    proxied: true,
    debug: true,
    path: '/myapp',
    ssl: {}
});

// 挂载PeerJS服务器
app.use('/myapp', peerServer);
app.use(cors());

// 提供静态文件服务（可选）
app.use(express.static('public'));

// 启动服务器
const PORT = 9000;
server.listen(PORT, () => {
    console.log(`Server is running on port ${PORT}`);
});
// 添加调试日志，以获取更多错误信息
peerServer.on('connection', (id) => {
    console.log(`New connection: ${id}`);
});

peerServer.on('disconnect', (id) => {
    console.log(`Disconnected: ${id}`);
});